#region <!--##session BOListWholeClass##-->
		/*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		codeGeneratorVariable_DisplayCode.Append(GeneralUsing() + Environment.NewLine);
		##-->*/
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EXtremecode.PresentationLayer;
namespace <!--##=RepositoryManager.Instance.Repository.ProjectName##-->.Aspx.<!--##=accessorName##-->
{
	public partial class <!--##=className##-->List : ListParentPage,IListPage
	{
		protected override string PageKey
        {
            get
            {
                return "<!--##=className##-->"; 
            }
        }
		
    
        protected override void OnLoad(EventArgs e)
		{
			//**register handlers for multirows actions
			OnSelectedRowAction += new OnSelectedRowActionDelegate(<!--##=className##-->List_OnSelectedRowAction);
			OnSelectedRowsActionComplete += new OnSelectedRowsActionCompleteDelegate(<!--##=className##-->List_OnSelectedRowsActionComplete);
			OnSelectedRowsActionFailed += new OnSelectedRowsActionFailedDelegate(<!--##=className##-->List_OnSelectedRowsActionFailed);    
        
			
			//**set grid key here.
			Grid.DataKeyNames = new string[] {
			/*<!--##
				string qoma="";			  
                foreach(string keyField in gridKey.Split(','))
                {
			##-->*/
					<!--##=qoma##--><!--##=className##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(keyField)##-->
			/*<!--##
					qoma = ","; 
                }
		    ##-->*/
			};

			base.OnLoad(e);
        }	
		   
		/*<!--##
		 codeGeneratorVariable_DisplayCode.Append(BOListPopulateListControls() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BOListPopulateBOCollection() + Environment.NewLine);
		 codeGeneratorVariable_DisplayCode.Append(BOListRowToControl() + Environment.NewLine);
		##-->*/

		#region IListPage Members
		/*<!--##
		codeGeneratorVariable_DisplayCode.Append(BOListPopulateSearchPanel() + Environment.NewLine);
		##-->*/
		BusinessObjectCollection IPage.BOCollection
		{
			get
			{
				BusinessObjectCollection col = <!--##=className##-->Collection.NewInstance;
				
				/** Custom Region Start [BOCollection] **/
				
				//--set default sorting.
				col.SortedBy = "<!--##=gridSortedBy##-->";

				//--set paging params if required.
				col.UsePaging = true;
				//col.PageSize = 2;
				
				/** Custom Region End **/

				return col;
			}
		}
		public string EntityName
		{
			get
			{
				return "<!--##=entityName##-->";
			}
		}

		public string ResourceName
		{
			get
			{

				return "<!--##=className##-->";
			}
		}
		public GridView Grid
		{
			get
			{
				return gv<!--##=className##-->;
			}
		}

		public IPager Pager
		{
			get
			{
				return pager<!--##=className##-->;
			}
		}

		public IButtonControl SearchButton
		{
			get
			{
				return btnSearch; ;
			}
		}

		public new string Title
		{
			get
			{
				return ResourceProvider.GetResourceString(ResourceName,"PageTitle");
			}
		}
		public MultiView MVSearchResult
		{
			get
			{
				return mvSearchResult;
			}
		}

		public MultiView MVMessage
		{
			get
			{
				return mvMessage;
			}
		}


    #endregion
	
		
		public void DeleteRow(DataKey dataKey,bool transactionBased)
		{
			<!--##=className##-->Collection col = <!--##=className##-->Collection.Instance;
				/*<!--##
					foreach(string keyField in gridKey.Split(','))
					{
				##-->*/
				col[<!--##=className##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(keyField)##-->] = dataKey[<!--##=className##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(keyField)##-->];
							/*<!--##
									qoma = ","; 
								}
							##-->*/
				col.DeleteRecords();

		}



		//**Event Handlers
		protected void btnSearch_Click(object sender, EventArgs e)
		{
			PopulateBOCollection();

			if (Pager != null)
			{
				BusinessObjectCollection col = GetBOCollectionForList();
				Pager.TotalRecords = col.GetRecordCount();
				Pager.CurrentPageNumber = col.PageNumber = 1;
			}

			BindData();
		}
		protected void gv<!--##=className##-->_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			switch (e.Row.RowType)
			{
				case DataControlRowType.DataRow:
					   <!--##=className##-->DataRow row = ((DataRowView)e.Row.DataItem).Row as <!--##=className##-->DataRow;
					   RowToControl(e.Row, row);
				break;

				case DataControlRowType.Header:
				break;

			}
		}

		protected void gv<!--##=className##-->_RowCommand(object sender, GridViewCommandEventArgs e)
		{
			int rowIndex = 0;
			GridView grid = sender as GridView;
			DataKey dataKey = null;
			if (e.CommandArgument != null &&
				int.TryParse(e.CommandArgument.ToString(), out rowIndex) && 
				rowIndex >= 0 && rowIndex <= grid.Rows.Count)
			{
				dataKey = grid.DataKeys[rowIndex];
			}

			switch(e.CommandName)
			{
				case "Edit":
					string queryString = string.Empty; 
			/*<!--##
				string seperator = " + \"&\" + ";
				if(gridKey!=string.Empty)
				{
			##-->*/
					queryString =  
			/*<!--##			  
					string[] strs=gridKey.Split(',');
					for(int i=0;  i<strs.Length; i++)
					{
						string keyField = strs[i];
						if(i == strs.Length-1)
						{
							seperator = ";";
						}
			##-->*/		
						string.Format("{0}={1}",
							<!--##=className##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(keyField)##-->,
							dataKey[<!--##=className##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(keyField)##-->]) <!--##=seperator##-->
			/*<!--##
						 
					}
					
				}	
		    ##-->*/

					Response.Redirect(string.Format("<!--##=className##-->Edit.aspx?Update=true&{0}",queryString),true);
					break;
				case "Delete":
					DeleteRow(dataKey,false);
					DoOnSuccessfullDelete();
					break;


			}
		}
		protected void gv<!--##=className##-->_RowCreated(object sender, GridViewRowEventArgs e)
		{
			switch (e.Row.RowType)
			{
				case DataControlRowType.DataRow:
                
					//delete button
					ImageButton btnDelete = e.Row.FindControl("btnDelete") as ImageButton;
					btnDelete.Attributes.Add("onclick",
						string.Format("if (!confirm('{0}')) return false;",
							ResourceProvider.GetGeneralResourceString("Message_WantToDeleteThis")));

					break;

				case DataControlRowType.Header:
					//delete selected button
					ImageButton btnDeleteSelected = e.Row.FindControl("btnDeleteSelected") as ImageButton;
					btnDeleteSelected.Attributes.Add("onclick",
						string.Format("if (!confirm('{0}')) return false;",
							ResourceProvider.GetGeneralResourceString("Message_WantToDeleteSelected")));

					break;

			}
		}

		public void gv<!--##=className##-->_RowEditing(object sender, GridViewEditEventArgs e)
		{
		}

		public void gv<!--##=className##-->_RowDeleting(object sender, GridViewDeleteEventArgs e)
		{

		}
		
		protected void btnWordExport_Click(object sender, ImageClickEventArgs e)
		{
			ExportListTo(ExportFormat.Word);
		}
		protected void btnExcelExport_Click(object sender, ImageClickEventArgs e)
		{
			ExportListTo(ExportFormat.Excel);
		}

		private void DoOnSuccessfullDelete()
		{
			Response.Redirect("<!--##=className##-->List.aspx",true);
		}
		private void DoOnSuccessfullMultiDelete()
		{
			Response.Redirect("<!--##=className##-->List.aspx",true);
		}

		void <!--##=className##-->List_OnSelectedRowsActionFailed(string actionName)
		{
			switch (actionName)
			{
				case "DeleteSelected":
					DataAccessor.RollbackTransaction();
					break;
			}
		}

		void <!--##=className##-->List_OnSelectedRowsActionComplete(string actionName)
		{
			switch (actionName)
			{
				case "DeleteSelected":
					DataAccessor.CommitTransaction();
					break;
			}
		}

		void <!--##=className##-->List_OnSelectedRowAction(string actionName, DataKey key)
		{
			switch (actionName)
			{
				case "DeleteSelected":
					DeleteRow(key, true);
					break;
			}
		}
	}
}
	
<!--##/session##-->
#endregion

#region <!--##session BOListPopulateListControls##-->
        /*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
				
		//overriding entity.
		Entity entityBOPage =  RepositoryManager.Instance.Entities["BOPage",entityName];
		Entity entityBOListSearch =  RepositoryManager.Instance.Entities["BOListSearch",entityName];
		if(entityBOPage != null)
		{
			entityBOPage.OverridingEntity = entityBOListSearch;
		}
		entity.OverridingEntity = entityBOPage;

		##-->*/
        private void PopulateListControls()
        {
			IListControl ctrl = null;
        /*<!--##
        foreach(string entityFieldKey in entity.Fields.Keys)
        {
            Entity.Field entityField = entity.Fields[entityFieldKey];
            <%@EntityFieldIncludes%> 
            if(listTable != string.Empty && displayed)
            {
			codeGeneratorVariable_DisplayCode.Append(Environment.NewLine + Environment.NewLine);
        ##-->*/
            //**<!--##=entityFieldName##-->
			ctrl = <!--##=FreeHash.ControlPrefix[listControl]##--><!--##=property##-->;
			<!--##=listTableCollectionName##--> col<!--##=property##--> = <!--##=listTableCollectionName##-->.Instance;
			ctrl.Enumerable=col<!--##=property##-->;
			ctrl.FormatString = "<!--##=formatString##-->";
			ctrl.KeyField = <!--##=listTableClassName##-->.FieldNames.<!--##=listTableKeyFieldConstant##-->;
			ctrl.DisplayFieldList = new string[] {
			/*<!--##
				string qoma="";			  
                foreach(string displayField in listTableDisplayFields.Split(','))
                {
			##-->*/
					<!--##=qoma##--><!--##=listTableClassName##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(displayField)##-->
			/*<!--##
					qoma = ","; 
                }
		    ##-->*/
			};
			ctrl.DataBind();
           
            
        /*<!--##
            }  
        }
		##-->*/
		}
<!--##/session##-->
#endregion

#region <!--##session BOListPopulateBOCollection##-->
        /*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
		
		//overriding entity.
		Entity entityBOPage =  RepositoryManager.Instance.Entities["BOPage",entityName];
		Entity entityBOListSearch =  RepositoryManager.Instance.Entities["BOListSearch",entityName];
		if(entityBOPage != null)
		{
			entityBOPage.OverridingEntity = entityBOListSearch;
		}
		entity.OverridingEntity = entityBOPage;
		
		##-->*/
        private void PopulateBOCollection()
        {
            <!--##=collectionName##--> col = GetBOCollectionForList() as <!--##=collectionName##-->;
            col.Refresh();
            FilterPair.Clear();
            /*<!--##
            foreach(string entityFieldKey in entity.Fields.Keys)
            {
                Entity.Field entityField = entity.Fields[entityFieldKey];
                <%@EntityFieldIncludes%> 
				string strNullable = (isValueType)? "?": string.Empty;
				codeGeneratorVariable_DisplayCode.Append(Environment.NewLine + Environment.NewLine);
                if(dataType!="shortbinary" && dataType!="binary" && displayed)
                {
					 string usedControl = (listTable == string.Empty)? webControl: listControl;
					 if(!usingRange)
					 {
            ##-->*/
			//**<!--##=entityFieldName##-->
            if (<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value != null)
            {
			/*<!--##
						if(usingTime)
						{
            ##-->*/	
				DateTime dtFrom = Convert.To<!--##=cSharpFrameworkDataType##-->(<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value);
				DateTime dtTo = dtFrom.AddDays(1).AddMilliseconds(-1);// last millisecond of this day;
				col.<!--##=property##-->_From = dtFrom;
				col.<!--##=property##-->_To = dtTo;
			/*<!--##
						}
						else
						{	 			
			##-->*/
				col.<!--##=property##--> = Convert.To<!--##=cSharpFrameworkDataType##-->(<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value);
			/*<!--##
						} 
			##-->*/  
				FilterPair.Add(new Pair(lbl<!--##=property##-->.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Text));
            } 
			/*<!--##
					}
					else //user range
					{
			##-->*/
			//**<!--##=entityFieldName##-->
            if (<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Value != null)
            {
            	col.<!--##=property##-->_From = Convert.To<!--##=cSharpFrameworkDataType##-->(<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Value);
			    FilterPair.Add(new Pair(lbl<!--##=property##-->_From.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Text));
            } 

			if (<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Value != null)
            {
            /*<!--##
						if(usingTime)
						{
            ##-->*/	
				DateTime dt = Convert.To<!--##=cSharpFrameworkDataType##-->(<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Value);
				dt = dt.AddDays(1).AddMilliseconds(-1);// last millisecond of this day;
				col.<!--##=property##-->_To = dt;
			/*<!--##
						}
						else
						{	 			
			##-->*/
				col.<!--##=property##-->_To = Convert.To<!--##=cSharpFrameworkDataType##-->(<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Value);
			/*<!--##
						} 
			##-->*/
			    FilterPair.Add(new Pair(lbl<!--##=property##-->_To.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Text));
            } 

			/*<!--##					
					}
		    	}  
            }
		    ##-->*/
		}
<!--##/session##-->
#endregion

#region <!--##session BOListRowToControl##-->
        /*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
								
		//overriding entity.
		Entity entityBOPage =  RepositoryManager.Instance.Entities["BOPage",entityName];
		Entity entityBOListGrid =  RepositoryManager.Instance.Entities["BOListGrid",entityName];
		if(entityBOPage != null)
		{
			entityBOPage.OverridingEntity = entityBOListGrid;
		}
		entity.OverridingEntity = entityBOPage;

		##-->*/
		protected void RowToControl(Control control, <!--##=className##-->DataRow row)
		{
            /*<!--##
            foreach(string entityFieldKey in entity.Fields.Keys)
            {
                Entity.Field entityField = entity.Fields[entityFieldKey];
                <%@EntityFieldIncludes%> 
				if(!displayed)
				{
					continue;
				}
				if(dataType == "shortbinary" || dataType == "binary")
				{
					//will handle it later
					continue;
				}
				codeGeneratorVariable_DisplayCode.Append(Environment.NewLine + Environment.NewLine);
				string usedControl = (listTable == string.Empty)? webControl: listControl;
                if(listTable == string.Empty)
                {
            ##-->*/

			//**<!--##=entityFieldName##-->

			<!--##=usedControl##--> <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##--> = control.FindControl("<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->") as <!--##=usedControl##-->;
			if (<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##--> != null)
			{
				<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value = <!--##=strDecimalCast##--> row.Value_<!--##=property##-->;
			}
			/*<!--##
				}  
				else  //for list control
				{
            ##-->*/

			//**<!--##=entityFieldName##-->

			<!--##=usedControl##--> <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##--> = control.FindControl("<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->") as <!--##=usedControl##-->;
			if (<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##--> != null)
			{
				<!--##=usedControl##--> ctrl =  <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->;
				if (row.Value_<!--##=property##--> != null)
				{
					<!--##=listTableCollectionName##--> col = <!--##=listTableCollectionName##-->.Instance;
					ctrl.Enumerable=col;
					ctrl.FormatString = "<!--##=formatString##-->";
					ctrl.IsRequired = true;
					ctrl.KeyField = <!--##=listTableClassName##-->.FieldNames.<!--##=listTableKeyFieldConstant##-->;
					ctrl.DisplayFieldList = new string[] {
			/*<!--##
					string qoma="";			  
					foreach(string displayField in listTableDisplayFields.Split(','))
					{
			##-->*/
						<!--##=qoma##--><!--##=listTableClassName##-->.FieldNames.<!--##=StringProcessor.ConstantNStatic(displayField)##-->
			/*<!--##
						qoma = ","; 
					}
		    ##-->*/
					};
					col.<!--##=listTableKeyFieldProperty##--> = row.Value_<!--##=property##-->;
					ctrl.DataBind();
                    ctrl.Value = row.Value_<!--##=property##-->;

				}
				else
				{
					ctrl.Value = null;
				}
			}
            /*<!--##
                }  
			##-->*/
			
			/*<!--##	
            }
		    ##-->*/
		}
<!--##/session##-->
#endregion

#region <!--##session BOListPopulateSearchPanel##-->
        /*<!--##
		Entity entity = RepositoryManager.Instance.ActiveEntity;
		<%@EntityIncludes%>
				
		//overriding entity.
		Entity entityBOPage =  RepositoryManager.Instance.Entities["BOPage",entityName];
		Entity entityBOListSearch =  RepositoryManager.Instance.Entities["BOListSearch",entityName];
		if(entityBOPage != null)
		{
			entityBOPage.OverridingEntity = entityBOListSearch;
		}
		entity.OverridingEntity = entityBOPage;

		##-->*/
        public void PopulateSearchPanel()
        {
            <!--##=collectionName##--> col = GetBOCollectionForList() as <!--##=collectionName##-->;
            if (!Page.IsPostBack)
			{
				//we can remove this check because Populating of search panel occurs only when isPostBack 
				//property is false.
				PopulateListControls();
			}
			FilterPair.Clear();
            /*<!--##
            foreach(string entityFieldKey in entity.Fields.Keys)
            {
                Entity.Field entityField = entity.Fields[entityFieldKey];
                <%@EntityFieldIncludes%> 

				codeGeneratorVariable_DisplayCode.Append(Environment.NewLine + Environment.NewLine);
                if(dataType!="shortbinary" && dataType!="binary" && displayed)
                {
					 string usedControl = (listTable == string.Empty)? webControl: listControl;
					 if(!usingRange)
					 {
					  string strFrom = (usingTime)? "_From": string.Empty;
            ##-->*/
			//**<!--##=entityFieldName##-->
            if (col.<!--##=property##--><!--##=strFrom##--> != null)
            {
            	<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value = <!--##=strDecimalCast##--> col.<!--##=property##--><!--##=strFrom##-->;
			    FilterPair.Add(new Pair(lbl<!--##=property##-->.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Text));
            }
			else
			{
				<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->.Value = null;
			} 
			/*<!--##
					}
					else //using range
					{ 
			##-->*/
			//**<!--##=entityFieldName##-->
			if (col.<!--##=property##-->_From != null)
            {
            	<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Value = <!--##=strDecimalCast##--> col.<!--##=property##-->_From;
			    FilterPair.Add(new Pair(lbl<!--##=property##-->_From.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Text));
            }
			else
			{
				<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_From.Value = null;
			} 

			if (col.<!--##=property##-->_To != null)
            {
            	<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Value = <!--##=strDecimalCast##--> col.<!--##=property##-->_To;
			    FilterPair.Add(new Pair(lbl<!--##=property##-->_To.Text, <!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Text));
            }
			else
			{
				<!--##=FreeHash.ControlPrefix[usedControl]##--><!--##=property##-->_To.Value = null;
			} 


			/*<!--##
					} 
		    	}  
            }
		    ##-->*/
		}	
<!--##/session##-->
#endregion


